package com.shanling.shanlingcontroller.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.WindowManager;

import com.shanling.shanlingcontroller.R;
import com.shanling.shanlingcontroller.base.BaseAppCompatActivity;
import com.shanling.shanlingcontroller.base.BaseMVPActivity;
import com.shanling.shanlingcontroller.bean.EventCenter;
import com.shanling.shanlingcontroller.bean.LoginBean;
import com.shanling.shanlingcontroller.bean.MybluetoothDevice;
import com.shanling.shanlingcontroller.persenter.LoginPersenter;
import com.shanling.shanlingcontroller.persenter.contract.LoginContract;

import org.litepal.LitePal;

import java.util.List;

public class SplashActivity extends BaseAppCompatActivity {
    private boolean isFrist;
    private Handler handler;//13767972854

    @Override
    protected void initViewsAndEvents() {
        // 设置全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        handler = new Handler();
        isFrist = preferenceUtil.getIsFrist();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                jumpActivity();
            }
        }, 400);

    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initData() {
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected void onEventComing(EventCenter eventCenter) {

    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    private void jumpActivity() {

   //   if (TextUtils.isEmpty(preferenceUtil.getUserName())) {
//////            if(isFrist){
//////              toActivity(GuideActivity.class);
//////            }else {
//////                toActivity(LoginActivity.class);
//////            }
           toActivity(LoginActivity.class);
   // } else {
            List<MybluetoothDevice> mybluetoothDevices = LitePal.findAll(MybluetoothDevice.class);
            if (mybluetoothDevices.size() == 0) {
                toActivity(BleActivity.class);
            } else {
                toActivity(MainActivity.class);
            }
      //  }
    }
    private void toActivity(Class clazz) {
        Intent intent = new Intent(this, clazz);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in,
                R.anim.fade_out);
        finish();
    }

    @Override
    public void onBackPressed() {
        handler.removeCallbacksAndMessages(null);
        finish();
    }
}
